<?php
/**
 * @class GiftController
 * @name 礼物管理
 * @author martinsun syh@sunyonghong.com
 */
namespace app\stream\controller;
use app\common\controller\Api;
class Gift extends Api
{
    protected $mod = '';
    protected $exchange_list = [];
    /**
     * @name 初始化方法
     */
    protected function _initialize(){
        parent::_initialize();
        $this->mod = model('stream/Gift');
    }
    /**
     * @name 未定的接口
     * @return array 
     */
    public function _empty(){
        return getApiErrorCode('00404');
    }
    /**
     * @name 赠送礼物
     */
    public function giftGiving(){
        $auth = self::checkApi(['usid','count','gift_code']);
        if($auth !== true) return $this->api_info;
        //房间检测
        $stream_uid = model('open/User')->getUidByUsid($this->usid);
        if($stream_uid == $this->uid){
            return ['code'=>'70401','message'=>'不能赠送给自己噢'];
        }
        if($stream_uid){
		   $this->to_uid = $stream_uid;
		   $res = $this->mod->do_haddle_give($this->data);
           if(!$res){
             return ['code'=>'70401','message'=>$this->mod->getError()];
           }else{
            return ['code'=>'00000','message'=>'赠送成功'];
           }
		}
        return ['code' => '70401','message'=>'赠送礼物失败,请稍后再试'];
        
    }
    /**
     * @name 点赞
     */
    public function diggZan(){
        $auth = self::checkApi(['usid','count']);
        if($auth !== true) return $this->api_info;
        //房间检测
        $stream_uid = model('open/User')->getUidByUsid($this->usid);
        if($stream_uid){
		   $this->to_uid = $stream_uid;
           if($this->to_uid == $this->uid){
                return ['code'=>'70401','message'=>'不能给自己点赞哦'];
           }
		   $res = $this->mod->do_haddle_zan($this->data);
           if(!$res){
             return ['code'=>'70401','message'=>$this->mod->getError()];
           }else{
             return ['code'=>'00000','message'=>'处理成功'];
           }
		}
        return ['code' => '70401','message'=>'处理失败,请稍后再试'];
    }
    /**
     * @name 获取礼物赠送排行榜
     */
    public function getGiftTopList(){
        $st = self::checkApi(['usid']);
        if(true !== $st) return $this->api_info;
        $limit = (int)$this->limit ?:10;
        $list = $this->mod->getGiftTopList($this->usid,$limit);
        return ['code'=>'00000','data'=>$list];
    }
    /**
     * @name 获取主播排行榜
     */
    public function getPresenterTopList(){
        $st = self::checkApi();
        if(true !== $st) return $this->api_info;
        $limit = (int)$this->limit ?:10;
        $list = $this->mod->getPresenterTopList($limit);
        return ['code'=>'00000','data'=>$list];
    }
}
